﻿using System;
using System.Drawing;

namespace MentalAlchemy.Molecules.Image
{
	public class Const
	{
		public const float CONTRAST_FACTOR_MIN = -100;
		public const float CONTRAST_FACTOR_MAX = 100;
		public const int GRAYLEVELS_COUNT = 256;
		public const int GRAYLEVEL_MAX = 255;
		public const int GRAYLEVEL_MIN = 0;
		public const float MAX_GRAYSCALE_ENTROPY = 5.545177f;
		public const float GRAYSCALE_R_COEFF = 0.212671f;
		public const float GRAYSCALE_G_COEFF = 0.715160f;
		public const float GRAYSCALE_B_COEFF = 0.072169f;
		public const float BRIGHTNESS_RATE = 0.01f;	// Weber constant
		public static readonly float BRIGHTNESS_RATE_SQRT = (float)Math.Sqrt (BRIGHTNESS_RATE);	// Square root from Weber constant.
		public static readonly float BRIGHTNESS_RATE_EXPMUL = (float)Math.E * BRIGHTNESS_RATE;	// Weber constant multiplied on the Euler's number.
		public static readonly float BRIGHTNESS_RATE_EXP = (float)Math.Exp(BRIGHTNESS_RATE);	// Exponent for the Weber constant.

		public const float NOISE_RATE_MIN = 0.0f;
		public const float NOISE_RATE_MAX = 100.0f;
		public const int RADIUS_MIN = 1;

		public const string IMAGE_FILE_FILTER = "Image Files(*.BMP;*.TIFF;*.JPG;*.GIF)|*.BMP;*.TIFF;*.JPG;*.GIF|All files (*.*)|*.*";
		public const string SAVE_IMAGE_FILE_FILTER = "*.BMP|*.BMP|*.TIFF|*.TIFF|*.JPG|*.JPG|*.GIF|*.GIF";
		public static readonly string[] IMG_EXTENSIONS = { "BMP", "JPG", "JPEG", "GIF", "TIF", "TIFF", "PNG" };
		public const string FOLDERS_SEPARATOR = "\\";

		public static string[] ImageExtensions
		{
			get { return IMG_EXTENSIONS; }
		}
	}

	/// <summary>
	/// Generic interface to describe elements owning a color scale.
	/// </summary>
	public interface IColorScaleOwner
	{
		ColorScale ColorScale { get; set; }
		
		void InvalidateImage();
	}

	namespace Struct
	{
		public class EdgeInfo
		{
			private int[] edgeFreq = new int[Const.GRAYLEVELS_COUNT];
			private int weakEdgeCount = 0;
			private int mediumEdgeCount = 0;
			private int strongEdgeCount = 0;
			private float meanBrightness = 0.0f;
			private float weakEdgeRate = 0;
			private float mediumEdgeRate = 0;
			private float strongEdgeRate = 0;

			public float MeanBrightness
			{
				get { return meanBrightness; }
				set { meanBrightness = value; }
			}
			public int[] EdgeFreq
			{
				get { return edgeFreq; }
				set { edgeFreq = value; }
			}
			public int WeakEdgeCount
			{
				get { return weakEdgeCount; }
				set { weakEdgeCount = value; }
			}
			public int MediumEdgeCount
			{
				get { return mediumEdgeCount; }
				set { mediumEdgeCount = value; }
			}
			public int StrongEdgeCount
			{
				get { return strongEdgeCount; }
				set { strongEdgeCount = value; }
			}
			public float WeakEdgeRate
			{
				get { return weakEdgeRate; }
				set { weakEdgeRate = value; }
			}
			public float MediumEdgeRate
			{
				get { return mediumEdgeRate; }
				set { mediumEdgeRate = value; }
			}
			public float StrongEdgeRate
			{
				get { return strongEdgeRate; }
				set { strongEdgeRate = value; }
			}
		}

		//public struct ImageParams
		//{
		//    public int classID;
		//    public float entropy;
		//    public float hueEntropy;
		//    public float meanBrightness;
		//    public float mediumEdgesRate;
		//    public float satEntropy;
		//    public float strongEdgesRate;
		//    public float weakEdgesRate;
		//}

		/// <summary>
		/// [atomic]
		/// 
		/// Structure for circle marker.
		/// </summary>
		public struct CircleMarker
		{
			public Point point;
			public int radius;

			public CircleMarker(int x, int y, int r)
			{
				point = new Point(x, y);
				radius = r;
			}
		}

		/// <summary>
		/// [atomic]
		/// 
		/// Structure to represent activity (or intensity) property stats.
		/// </summary>
		//public struct ActivityProperties
		//{
		//    public int total;
		//    public int max;
		//    public int min;
		//    public int median;
		//    public float mean;
		//    public float variance;
		//}
	}
}